package com.example.dbsample.config.apollo;

import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.Assert;

public class CommonApolloConfig {
    private static Config applicationApolloConfig = ConfigService.getConfig("application");
    public static String getApplicationConfigByKey(String key) {
        return applicationApolloConfig.getProperty(key, "");
    }

    private static Config apolloConfig = ConfigService.getConfig("application");

    public static String getHostByAppName(String appName, String businessLine) {
        Assert.isTrue(StringUtils.isNotBlank(appName), "CommonApolloConfig.getHostByAppName的入参appName不能为空");
        //String businessLine = ThreadLocalCon
        businessLine = StringUtils.defaultString(businessLine, "sample1").toLowerCase();
        String key = String.format("conf.sample.%s.%s", appName.toLowerCase(), businessLine);
        return apolloConfig.getProperty(key, "");
    }
}
